home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / p063b9s.zip / UNIT / OUTINFO.PAS < prev    next >
Pascal/Delphi Source File  |  1997-03-02  |  13KB  |  411 lines

  1. UNIT OutInfo;
  2. {╔══════════════════════════════════════════════════════════════════════════╗}
  3. {║ Information about outbound traffic            Last changed: 02.03.97  SA ║}
  4. {║                                                                          ║}
  5. {║                         (C) Copyright 1989-97 by                         ║}
  6. {║       Dan Wulff, Jens Sandalgaard, Steen Christensen & S¢ren Ager        ║}
  7. {║                                                                          ║}
  8. {║ This source may NOT be given to anybody, without the written permission  ║}
  9. {║ from The Portal Team.                                                    ║}
  10. {╚══════════════════════════════════════════════════════════════════════════╝}
  11. {$I POPDEFS.INC}
  12.  
  13. INTERFACE
  14.  
  15. USES Use32;
  16.  
  17. PROCEDURE GetOutboundInformation;
  18. PROCEDURE ExpandOutboundEntry;
  19.  
  20. IMPLEMENTATION
  21.  
  22. USES Dos, OpCrt, OpString, OpRoot, OpDate, OpWindow, OpKey, ApTimer,
  23. {$IFDEF OS2}
  24.      VpUtils,
  25. {$ENDIF}
  26.      PoPTypes, NodeList, MailUtil, StrUtil, OproUtil, KeyBoard, Com,
  27.      Display, Util, Globals, LogFile;
  28.  
  29.  
  30.   PROCEDURE GetOutboundInformation;
  31.   VAR
  32.     Escaped        : Boolean;
  33.     OutName,
  34.     ZoneOut,ss     : PathStr;
  35.     SRec, sr,
  36.     sr3            : SearchRec;
  37.     i,
  38.     GlobZone, GlobNet,
  39.     GlobNode,Io    : Integer;
  40.     p              : STRING[4];
  41.     WaitWin        : PWait;
  42.  
  43.     FUNCTION CheckMType(MType: Byte): Boolean;
  44.     VAR
  45.       i : Byte;
  46.     BEGIN
  47.       CheckMType:=False;
  48.       FOR i:=0 TO 7 DO
  49.         IF (1 SHL Cfg.Modem.ModemType[i].Bit) AND MType<>0 THEN
  50.         BEGIN
  51.           CheckMType:=NOT Cfg.Modem.ModemType[i].DialOut;
  52.           Break;
  53.         END;
  54.     END;
  55.  
  56.     PROCEDURE AddToList(CONST FName: S12; FSize, FileTime: LongInt);
  57.     LABEL
  58.       Again;
  59.     VAR
  60.       i              : Integer;
  61.       DT             : DateTime;
  62.       TmpAge         : LongInt;
  63.       D,M,Y          : Integer;
  64.       Ext            : S3;
  65.       NlRec          : NodeListRecType;
  66.       TmpPtr         : POutList;
  67.       TmpAdr         : TFidoAddress;
  68.     BEGIN
  69.       WITH TmpAdr DO
  70.       BEGIN
  71.         Zone:=GlobZone;
  72.         IF GlobNet=0 THEN
  73.         BEGIN
  74.           Val('$'+Copy(sr.Name, 1, 4), Net, i);
  75.           Val('$'+Copy(sr.Name, 5, 4), Node, i);
  76.           Point:=0;
  77.         END ELSE
  78.         BEGIN
  79.           Net:=GlobNet;
  80.           Node:=GlobNode;
  81.           Val('$'+Copy(sr.Name, 5, 4), Point, i);
  82.         END;
  83.       END;
  84.       CLOutListPtr:=POutList(OutList^.Head);
  85.       WHILE (CLOutListPtr<>Nil) And NOT CmpAdr(CLOutListPtr^.Address,TmpAdr) DO
  86.         CLOutListPtr:=POutList(OutList^.Next(CLOutListPtr));
  87.       IF CLOutListPtr<>Nil THEN
  88.       BEGIN
  89.         CLOutListPtr^.Size:=CLOutListPtr^.Size+FSize;
  90.       END ELSE
  91.       BEGIN
  92.         New(CLOutListPtr, Init);
  93.         IF OutList^.Size=0 THEN
  94.           OutList^.Append(CLOutListPtr)
  95.         ELSE
  96.         BEGIN
  97.           TmpPtr:=POutList(OutList^.Head);
  98.           WHILE (TmpPtr<>Nil) And (Address2Sort(TmpPtr^.Address)<Address2Sort(TmpAdr)) DO
  99.             TmpPtr:=POutList(OutList^.Next(TmpPtr));
  100.           IF TmpPtr<>Nil THEN
  101.             OutList^.PlaceBefore(CLOutListPtr, TmpPtr)
  102.           ELSE
  103.             OutList^.Append(CLOutListPtr)
  104.         END;
  105.         WITH CLOutListPtr^ DO
  106.         BEGIN
  107.           Address:=TmpAdr;
  108.           Size:=FSize;
  109. Again:
  110.           IF FindNode(TmpAdr,NlRec) THEN
  111.           BEGIN
  112.             Baud:=NlRec.BaudRate;
  113.             Closed:=NlRec.SystemName[1]='<';
  114.             NoCMail:=(NlRec.Flags And nlf_CrashMail)=0;
  115.             Known:=True;
  116.             Cost:=NlRec.RealCost;
  117.             DontCall:=CheckMType(NlRec.ModemType);
  118.           END;
  119.           IF NoCMail THEN
  120.             IF NOT FindNodeInfo(NodesRec, TmpAdr) THEN
  121.             BEGIN
  122.               IF TmpAdr.Point<>0 THEN
  123.               BEGIN
  124.                 TmpAdr.Point:=0;
  125.                 GOTO Again;
  126.               END;
  127.               IF Cfg.Addresses[Cfg.MainAdrNum].Zone=Address.Zone THEN
  128.               BEGIN
  129.                 OpenFrom:=Cfg.ZMHStart;
  130.                 OpenTo:=Cfg.ZMHEnd;
  131.               END ELSE
  132.                 OpenTo:=HMSToTime(0, 0, 1);
  133.             END ELSE
  134.             BEGIN
  135.               IF NodesRec.Phone<>'' THEN
  136.               BEGIN
  137.                 Known:=True;
  138.                 Closed:=False;
  139.               END;
  140.               OpenFrom:=NodesRec.OpenFrom;
  141.               OpenTo:=NodesRec.OpenTo;
  142.             END;
  143.           FindUnDialable(TmpAdr, NC, BWZ);
  144.         END;
  145.       END;
  146.       I:=Pos('.', FName);
  147.       Ext:=Copy(FName, i+1, 3);
  148.       IF Ext='GLU' THEN
  149.         CLOutListPtr^.Glued:=True
  150.       ELSE
  151.       BEGIN
  152.         UnPackTime(FileTime,DT);
  153.         WITH DT DO
  154.           TmpAge:=Today-DMYToDate(Day,Month,Year);
  155.         IF TmpAge>CLOutListPtr^.Age THEN CLOutListPtr^.Age:=TmpAge;
  156.         IF FName<>'' THEN Inc(CLOutListPtr^.FilesToSend);
  157.         WITH CLOutListPtr^ DO
  158.         BEGIN
  159.           IF i <> 0 THEN
  160.           BEGIN
  161.             IF Ext = 'REQ' THEN Bits:=(Bits OR 32) ELSE
  162.               IF (Copy(Ext, 2, 2) = 'UT') OR (Pos(Copy(Ext, 1, 2), 'MO*TU*WE*TH*FR*SA*SU*') > 0) THEN
  163.                 Bits:=(Bits OR 64)
  164.               ELSE
  165.                 Bits:=(Bits OR 128);
  166.           END;
  167.           CASE sr.Name[10] OF
  168.             'C' : Bits:=Bits OR 4;
  169.             'H' : Bits:=Bits OR 16;
  170.             'D' : Bits:=Bits OR 2;
  171.             'F',
  172.             'O' : Bits:=Bits OR 1;
  173.             'I' : Bits:=Bits OR 8;
  174.           END;
  175.         END;
  176.       END;
  177.     END;
  178.  
  179.     PROCEDURE SearchDir;
  180.     VAR
  181.       f   : TBufTextFile;
  182.       e,i : Byte;
  183.       sr2 : SearchRec;
  184.       s   : STRING;
  185.  
  186.       FUNCTION SearchExt(x: Byte): {$IFDEF OS2} S4 {$ELSE} S3 {$ENDIF};
  187.       BEGIN
  188.         CASE x OF
  189.           1 : SearchExt:='REQ';
  190.           2 : SearchExt:='?UT';
  191.           3 : SearchExt:='GLU';
  192.           4 : SearchExt:='?LO';
  193.         END;
  194.       END;
  195.  
  196.     BEGIN
  197.       FOR e:=1 TO 4 DO
  198.       BEGIN
  199.         IF Escaped THEN Break;
  200.         FindFirst(ZoneOut+'????????.'+SearchExt(e), Archive, Sr);
  201. {$IFDEF OutDebug}
  202.         AddLog('!', 'Found: '+Sr.Name);
  203. {$ENDIF}
  204.         WHILE (DosError=0) AND NOT Escaped DO
  205.         BEGIN
  206.           IF (e<4) THEN
  207.           BEGIN
  208.             AddToList(Sr.Name, Sr.Size, Sr.Time);
  209.             IF ComPort^.KeyPressed OR ((CurrentEvent.typ AND etDynamic=0) AND PoPKeyPressed) THEN Escaped:=True;
  210.           END ELSE
  211.           BEGIN
  212.             IF f.Init(ZoneOut+Sr.Name, SOpenRead+ShareDenyNone, 10240) THEN
  213.             BEGIN
  214.               WHILE NOT f.EOF AND NOT Escaped DO
  215.               BEGIN
  216.                 f.ReadLn(s);
  217.                 IF (s<>'') AND (s[1]<>'~') THEN
  218.                 BEGIN
  219.                   IF s[1] IN ['#', '^'] THEN Delete(s, 1, 1);
  220.                   FindFirst(s, archive, sr2);
  221.                   IF DosError=0 THEN
  222.                     AddToList(sr2.Name,sr2.size,sr2.Time)
  223.                   ELSE
  224.                     AddLog(' ', 'Invalid entry in: '+ZoneOut+Sr.Name+' ('+s+')');
  225.                   FindClose(sr2);
  226.                 END;
  227.                 IF ComPort^.KeyPressed OR ((CurrentEvent.typ AND etDynamic=0) AND PoPKeyPressed) THEN Escaped:=True;
  228.               END;
  229.               f.Done;
  230.             END;
  231.             AddToList('', 0, sr.time);
  232.           END;
  233.           FindNext(Sr);
  234. {$IFDEF OutDebug}
  235.           AddLog('!', 'Found: '+Sr.Name);
  236. {$ENDIF}
  237.           WaitWin^.Animate;
  238.         END;
  239.         FindClose(Sr);
  240.       END;
  241.     END;
  242.  
  243.   BEGIN
  244.     Escaped:=ComPort^.KeyPressed OR (PoPKeyPressed AND (CurrentEvent.typ AND etDynamic=0));
  245.     Dispose(OutList, Done);
  246.     New(OutList, Init);
  247.     New(WaitWin, Init(12, 2, 'Scanning outbound'));
  248.     FindFirst(cfg.outbound+'.*', Directory, Srec);
  249. {$IFDEF OutDebug}
  250.     AddLog('!', 'Found: '+Srec.Name);
  251. {$ENDIF}
  252.     OutName:=JustFileName(cfg.outbound);
  253.     GlobNode:=0; GlobNet:=0;
  254.     StopClock;
  255.     WHILE (DosError=0) AND NOT Escaped DO
  256.     BEGIN
  257.       io:=0;
  258.       IF Srec.Name=OutName THEN
  259.         GlobZone:=Cfg.Addresses[Cfg.MainAdrNum].Zone
  260.       ELSE
  261.       BEGIN
  262.         p:=Copy(Srec.Name, Pos('.', Srec.Name)+1, 3);
  263.         Val('$'+p, GlobZone, io);
  264.         IF (GlobZone=Cfg.Addresses[Cfg.MainAdrNum].Zone) THEN
  265.         BEGIN
  266.           AddLog('!', 'Invalid outbound directory: '+SRec.Name);
  267.           FindNext(SRec);
  268. {$IFDEF OutDebug}
  269.           AddLog('!', 'Found: '+SRec.Name);
  270. {$ENDIF}
  271.           Continue;
  272.         END;
  273.       END;
  274.       IF (io=0) AND (GlobZone<>0) THEN
  275.       BEGIN
  276.         ZoneOut:=HoldAreaNameMunge(GlobZone,False);
  277.         SearchDir;
  278.         FindFirst(ZoneOut+'*.PNT',Directory,Sr3);
  279. {$IFDEF OutDebug}
  280.         AddLog('!', 'Found: '+Sr3.Name);
  281. {$ENDIF}
  282.         ss:=ZoneOut;
  283.         WHILE (DosError=0) AND NOT Escaped DO
  284.         BEGIN
  285.           ZoneOut:=AddBackSlash(ss+Sr3.Name);
  286.           Val('$'+Copy(sr3.Name, 1, 4), GlobNet, i);
  287.           Val('$'+Copy(sr3.Name, 5, 4), GlobNode, i);
  288.           SearchDir;
  289.           FindNext(Sr3);
  290. {$IFDEF OutDebug}
  291.           AddLog('!', 'Found: '+Sr3.Name);
  292. {$ENDIF}
  293.         END;
  294.         FindClose(Sr3);
  295.       END;
  296.       GlobNet:=0; GlobNode:=0;
  297.       FindNext(SRec);
  298. {$IFDEF OutDebug}
  299.       AddLog('!', 'Found: '+SRec.Name);
  300. {$ENDIF}
  301.     END;
  302.     FindClose(SRec);
  303.     StartClock;
  304.     CLOutListPtr:=POutList(OutList^.Head);
  305.     FLOutListPtr:=POutList(OutList^.Head);
  306.     Dispose(WaitWin, Done);
  307.     IF Escaped THEN
  308.     BEGIN
  309.       NewTimerSecs(OutboundReRead, 120);
  310.       MailToSend:=True;
  311.     END ELSE
  312.       NewTimerSecs(OutboundReRead, Cfg.OutReReadDelay);
  313.   END;
  314.  
  315.   PROCEDURE ExpandOutboundEntry;
  316.   LABEL
  317.     AllDone;
  318.   TYPE
  319.     DetailRec      = RECORD
  320.                        Name           : S12;
  321.                        Mode           : Char;
  322.                        after          : S8;
  323.                        size           : LongInt;
  324.                      END;
  325.     DetailTab      = ARRAY[1..200] OF DetailRec;
  326.   VAR
  327.     Detail         : ^DetailTab;
  328.     sr, sr1        : SEARCHREC;
  329.     f              : TBufTextFile;
  330.     i,num          : Integer;
  331.     s              : STRING;
  332.     spec           : Char;
  333.     Temp           : windowptr;
  334.     InKey          : Word;
  335.   BEGIN
  336.     IF OutList^.Size>0 THEN
  337.     BEGIN
  338.       New(Detail);
  339.       WITH CLoutlistPtr^ DO
  340.       BEGIN
  341.         mywin(Temp, 1, 8, 80, ScreenHeight, 2, 'Outgoing files for '+Address2Str(Address),False);
  342.         FindFirst(HoldFileName(Address,False)+'*', AnyFile, sr);
  343.         num:=0;
  344.         WHILE DosError = 0 DO
  345.         BEGIN
  346.           IF (Copy(sr.Name, 11, 2) = 'LO') OR (Copy(sr.Name, 11, 2) = 'EQ') THEN
  347.           BEGIN
  348.             IF f.Init(HoldAreaPath(Address,False)+sr.Name, SOpenRead+ShareDenyNone, 10240) THEN
  349.             BEGIN
  350.               WHILE NOT f.EoF DO
  351.               BEGIN
  352.                 f.ReadLn(s);
  353.                 S:=StUpCase(S);
  354.                 Inc(num);
  355.                 Detail^[num].Mode:=sr.Name[10];
  356.                 IF Detail^[num].Mode = 'F' THEN Detail^[num].Mode:='N';
  357.                 IF s[1] IN ['#', '^','~'] THEN
  358.                 BEGIN
  359.                   spec:=s[1];
  360.                   Delete(s, 1, 1);
  361.                 END ELSE spec:=#0;
  362.                 FindFirst(s, AnyFile, sr1);
  363.                 IF DosError = 0 THEN
  364.                 BEGIN
  365.                   Detail^[num].size:=sr1.Size
  366.                 END ELSE
  367.                   Detail^[num].size:=0;
  368.                 Detail^[num].Name:=JustFileName(s);
  369.                 CASE spec OF
  370.                   '^' : Detail^[num].after:='Erase';
  371.                   '#' : Detail^[num].after:='Trunc';
  372.                   '~' : Detail^[num].after:='Sent ';
  373.                   #0  : Detail^[num].after:='Keep ';
  374.                 END;
  375.               END;
  376.               f.Done;
  377.             END;
  378.           END ELSE
  379.             IF (Copy(sr.Name, 11, 2) = 'UT') AND (sr.Name[10] IN ['C', 'H', 'D', 'O','I']) THEN
  380.             BEGIN
  381.               Inc(num);
  382.               Detail^[num].Name:=sr.Name;
  383.               Detail^[num].Mode:=sr.Name[10];
  384.               Detail^[num].after:='TRUNC';
  385.               Detail^[num].size:=sr.size;
  386.             END;
  387.           FindNext(sr);
  388.         END;
  389.         FindClose(sr);
  390.         FOR i:=1 TO num DO
  391.           WITH Detail^[i] DO
  392.           BEGIN
  393.             Write(' '+CPad(Name,13)+' '+LongIntForm('##########',size)+' '+Mode+' '+after+CharStr(' ',5));
  394.             IF ((i MOD 30)=0) And (i<>Num) THEN
  395.             BEGIN
  396.               InKey:=WaitForAction(20);
  397.               IF ComPort^.KeyPressed OR (InKey=Esc) THEN GOTO AllDone;
  398.               ClrScr;
  399.             END ELSE
  400.               IF NOT Odd(i) THEN WriteLn;
  401.           END;
  402.         WaitForAction(20);
  403. AllDone:
  404.         KillWindow(Temp);
  405.       END;
  406.       Dispose(Detail);
  407.     END;
  408.   END;
  409.  
  410. END.
  411.